
import java.util.*;
class Solution {
    public void merge(int A[], int m, int B[], int n) {
        int p1 = m - 1; //如果这时m或n为0，那么p1或p2就会是-1，下面的代码就有越界风险！！！！
        int p2 = n - 1;
        if(p1 < 0) {
            for (int i = 0; i < n; i++) {
                A[i] = B[i];

            }
        }else {
            for (int i = m + n - 1; i >= 0 ; i--) {
                if(p2 < 0)
                {
                    break;
                }
                if(A[p1] < B[p2]) {
                    A[i] = B[p2];
                    p2--;
                }
                else {
                    A[i] = A[p1];
                    p1--;
                }
                if(p1 < 0)
                {
                    for (int j = 0; j < p2 + 1; j++) {
                        A[j] = B[j];

                    }
                    break;
                }
            }
        }

    }
}
public class Test1 {
}
